package com.supms.patrol.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.supms.patrol.domain.DailyInspectionItems;
import com.supms.patrol.service.IDailyInspectionItemsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 日常巡查项Controller
 * 
 * @author LiangHao
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/dailyInspectionItems")
public class DailyInspectionItemsController extends BaseController
{
    @Autowired
    private IDailyInspectionItemsService dailyInspectionItemsService;

    /**
     * 查询日常巡查项列表
     */
    @RequiresPermissions("patrol:dailyInspectionItems:list")
    @GetMapping("/list")
    public TableDataInfo list(DailyInspectionItems dailyInspectionItems)
    {
        startPage();
        List<DailyInspectionItems> list = dailyInspectionItemsService.selectDailyInspectionItemsList(dailyInspectionItems);
        return getDataTable(list);
    }

    /**
     * 导出日常巡查项列表
     */
    @RequiresPermissions("patrol:dailyInspectionItems:export")
    @Log(title = "日常巡查项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DailyInspectionItems dailyInspectionItems)
    {
        List<DailyInspectionItems> list = dailyInspectionItemsService.selectDailyInspectionItemsList(dailyInspectionItems);
        ExcelUtil<DailyInspectionItems> util = new ExcelUtil<DailyInspectionItems>(DailyInspectionItems.class);
        util.exportExcel(response, list, "日常巡查项数据");
    }

    /**
     * 获取日常巡查项详细信息
     */
    @RequiresPermissions("patrol:dailyInspectionItems:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dailyInspectionItemsService.selectDailyInspectionItemsById(id));
    }

    /**
     * 新增日常巡查项
     */
    @RequiresPermissions("patrol:dailyInspectionItems:add")
    @Log(title = "日常巡查项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DailyInspectionItems dailyInspectionItems)
    {
        return toAjax(dailyInspectionItemsService.insertDailyInspectionItems(dailyInspectionItems));
    }

    /**
     * 修改日常巡查项
     */
    @RequiresPermissions("patrol:dailyInspectionItems:edit")
    @Log(title = "日常巡查项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DailyInspectionItems dailyInspectionItems)
    {
        return toAjax(dailyInspectionItemsService.updateDailyInspectionItems(dailyInspectionItems));
    }

    /**
     * 删除日常巡查项
     */
    @RequiresPermissions("patrol:dailyInspectionItems:remove")
    @Log(title = "日常巡查项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dailyInspectionItemsService.deleteDailyInspectionItemsByIds(ids));
    }

    /**
     * 获取当前记录表的日常巡查记录
     */
    @GetMapping("/item/{dailyInspectionId}")
    public List<DailyInspectionItems> getDailyInspectionItem(@PathVariable Long dailyInspectionId) {
        return dailyInspectionItemsService.getDailyInspectionItemByDIId(dailyInspectionId);
    }

    /**
     * 添加日常巡查情况记录
     */
    @PostMapping("/addDailyInspectionEval")
    public AjaxResult addDailyInspectionEval(@RequestBody List<DailyInspectionItems> dailyInspectionItemsList)
    {
        return toAjax(dailyInspectionItemsService.insertDailyInspectionEval(dailyInspectionItemsList));
    }

    /**
     * 修改（更新）日常巡查情况记录
     */
    @PostMapping("/updateDailyInspectionEval")
    public AjaxResult updateDailyInspectionEval(@RequestBody List<DailyInspectionItems> dailyInspectionItemsList)
    {
        return toAjax(dailyInspectionItemsService.updateDailyInspectionEval(dailyInspectionItemsList));
    }
}
